# -*- coding: utf-8 -*-
#
# @Time    ： 2024/4/15  15:17
# @Auther  ： 徐良
# File     :  domainFunction.py
from typing import List
from dbService.db_service import get_model

# 数据类型列表
combox_TypeList = ['Integer', 'Float', 'String', 'Date', 'DateTime', 'Time']

# 数据类型列表
combox_AlignList = ['left', 'right', 'center']

# 用于网格方式的编辑控件
combox_WidgetGridList = ['check', 'BodyLineEditInt', 'BodyLineEditFloat',
                         'BodyLineEditStr', 'TextEditDialog', 'ComboxFree']
# 用于表单方式的编辑控件
combox_WidgetFormList = ['check', 'HeadLineEditInt', 'HeadLineEditFloat',
                         'HeadLineEditStr', 'EditPanel', 'LineEditPath', 'ComBox_Type',
                         'F7HeadLineEdit', 'CustCheckBox']

domain_list = ['', 'DomainList', 'str_widget_list', 'str_align_list', 'str_type_list']


class DomainList:
    _instance = None
    _initialized = False

    def __new__(cls):
        if cls._instance is None:
            cls._instance = super(DomainList, cls).__new__(cls)
        return cls._instance

    def __init__(self):
        if not DomainList._initialized:
            self._domainList = []
            DomainList._initialized = True

    def get_domain_list(self) -> List[str]:
        if not self._domainList:
            sql = "select FName from t_domain order by FName "
            model = get_model(sql)
            for row in range(0, model.rowCount()):
                self._domainList.append(model.record(row).value('FName'))

        return self._domainList


